package net.osc.web;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;

/**
 * 日期类型到json的格式转换
 * @author <a href=mailto:wu.peng@starit.com.cn>wu.peng</a> 2012-7-20
 *
 */
public class DefaultJsonDateSerializer extends JsonSerializer<Date>{ 
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 

    @Override 
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) 
            throws IOException, JsonProcessingException {
        String formattedDate = dateFormat.format(date); 
        gen.writeString(formattedDate); 
    }

} 